﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

using Odebrecht.WcfService.Configurations;
using Odebrecht.WcfService.Entities;

namespace Odebrecht.WcfService
{
    public class DatabaseContext : DbContext
    {
        #region Constructors

        public DatabaseContext()
            : base("DefaultConnection")
        {
            Configuration.ValidateOnSaveEnabled = true;
        }

        public DatabaseContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
            Configuration.ValidateOnSaveEnabled = true;
        }

        #endregion Constructors

        #region Properties

        public DbSet<Tarefa> Tarefa
        {
            get; set;
        }

        #endregion Properties

        #region Methods

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //Conventions

            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            //Configurations

            modelBuilder.Configurations.Add<Tarefa>(new TarefaConfiguration());

            base.OnModelCreating(modelBuilder);
        }

        #endregion Methods
    }
}